<template>
  <div class="mycharts">
    <div class="pidaiEcharts" id="pidaiEcharts"></div>
  </div>
</template>

<script>
// import echarts from "echarts";
// import { mapState } from 'vuex'
// import { getCemsData } from '@/api/line.js'
import { getCalcData } from '../../api/calcApi'
import { formCalcineData } from "../../api/minuteReportApi"
export default {
  data () {
    return {}
  },
  computed: {
    // ...mapState(['dialog'])
  },
  // watch: {
  //   cemsDataItem: {
  //     handler (a) {
  //       console.log(a)
  //       this.cemsData = a
  //       // console.log(this.productionData.data, 'aaaa');
  //       this.initDialogs()
  //       // console.log(b, 'bbbbb');
  //       // this.fullName = newName + ' ' + this.lastName;
  //     }
  //     // immediate: true
  //   },
  //   dialog () {
  //     this.$nextTick(() => {
  //       this.initDialogs()
  //       // console.log(1);
  //     })
  //   }
  // },
  mounted () {
    this.$nextTick(() => {
      this.initDialogs()
    })
  },
  methods: {
    async initDialogs () {
      this.$echarts.init(document.getElementById('pidaiEcharts')).dispose()
      const params = {
        code: '62a888b0d8a1cbe11b55b494'
      }
      const { data } = await formCalcineData(params)
      var pidaiData = data.data.data[0].info.D地沟皮带电流.data
      var pidaiTime = []

      // console.log(pidaiData)
      // console.log(pidaiTime)
      // console.log(data.data.data[0][1].Value[1].Value)
      // console.log(data.data.data[0][1].Value[0].Value[1].Value)
      // Object.values(data.data[0].info).forEach((item) => {
      //   chuchenData.push(item.data)
      // })
      data.data.data[0].info.D地沟皮带电流.time.forEach((item) => {
        pidaiTime.push(item.slice(5, -3))
      })
      // .replace(/\s*/g, '')
      const myChart = this.$echarts.init(
        document.getElementById('pidaiEcharts')
      ) // 初始化实例
      myChart.resize()
      const option = {
        // title: {
        //     show: false,
        //     text: '多线图',
        //     textStyle: {
        //         align: 'center',
        //         color: '#fff',
        //         fontSize: 20,
        //     },
        //     top: '5%',
        //     left: 'center',
        // },
        legend: {
          top: '5%',
          itemWidth: 15,
          itemHeight: 8,
          textStyle: {
            color: '#a6bde9',
            fontSize: 10
          }
        },
        tooltip: {
          trigger: 'axis',
          textStyle: {
            fontSize: 12
          },
          axisPointer: {
            lineStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: 'rgba(0, 255, 233,0)'
                  },
                  {
                    offset: 0.5,
                    color: 'rgba(255, 255, 255,1)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(0, 255, 233,0)'
                  }
                ],
                global: false
              }
            }
          }
        },
        grid: {
          top: '17%',
          left: '3%',
          right: '5%',
          bottom: '12%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          axisTick: { show: false },
          boundaryGap: false,
          data: pidaiTime,
          // 设置轴线的属性
          axisLabel: {
            interval: 2,
            formatter: function (value) {
              var ret = '' // 拼接加\n返回的类目项
              var maxLength = 6 // 每项显示文字个数
              var valLength = value.length // X轴类目项的文字个数
              var rowN = Math.ceil(valLength / maxLength) // 类目项需要换行的行数
              if (rowN > 1) {
                // 如果类目项的文字大于5,
                for (var i = 0; i < rowN; i++) {
                  var temp = '' // 每次截取的字符串
                  var start = i * maxLength // 开始截取的位置
                  var end = start + maxLength // 结束截取的位置
                  // 这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
                  temp = value.substring(start, end) + '\n'
                  ret += temp // 凭借最终的字符串
                }
                return ret
              } else {
                return value
              }
            },
            show: true,
            textStyle: {
              fontSize: 10 // 更改坐标轴文字大小
            }
          },
          axisLine: {
            lineStyle: {
              color: '#a6bde9'
            }
          }
        },
        yAxis: {
          min: 0,
          max: 400,
          boundaryGap: false,
          type: 'value',
          axisLabel: {
            textStyle: {
              color: '#a6bde9',
              fontSize: 10
            }
          },
          nameTextStyle: {
            color: '#fff',
            fontSize: 12,
            lineHeight: 40
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: '#283352',
              type: 'dashed'
            }
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#a6bde9'
            }
          },
          axisTick: {
            show: false
          }
        },
        series: [
          {
            name: 'I(A)',
            type: 'line',
            showSymbol: true,
            // symbol: 'image://./static/images/guang-circle.png',
            symbol: 'circle',
            symbolSize: 5,
            lineStyle: {
              normal: {
                width: 2,
                color: '#22C3AA'
              }
            },
            label: {
              show: false,
              position: 'top',
              textStyle: {
                color: '#fff',
                fontSize: 14
              }
            },
            itemStyle: {
              color: '#22C3AA',
              borderColor: 'rgb(0,115,100)',
              borderWidth: 0,
              shadowColor: 'rgba(0, 0, 0, 0)',
              shadowBlur: 0,
              shadowOffsetY: 0,
              shadowOffsetX: 0
            },
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: 'rgba(46, 204, 113,0.4)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(255,188,13, 0)'
                  }
                ],
                global: false // 缺省为 false
              }
            },
            tooltip: {
              show: true
            },
            data: pidaiData
          }
        ]
      }
      myChart.setOption(option)
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    }
  }
}
</script>

<style scoped>
.pidaiEcharts {
  height: 95%;
  width: 100%;
  /* display: flex; */
  /* padding-top: 7%; */
}

.mycharts {
  height: 100%;
  width: 100%;
  /* background-color: rgba(1, 131, 196, 0.05); */
  /* border: solid 1px rgba(1, 131, 196, 0.25); */
  /* background-color: rbga(); */
  /* border-radius: 10%; */
  /* border-top-left-radius: 10%;
  border-top-right-radius: 0%;
  border-bottom-right-radius: 10%;
  border-bottom-left-radius: 0%; */
}
</style>
